package com.summer.main;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test {
	
	public static void main(String[] args) {
		Method[] methods = A.class.getDeclaredMethods();
		Method oMethod = null;
		Method oMethod1 = null;
		for(Method method :methods){
			if(method.getName().equals("showA")){
				oMethod = method;
			}
			if(method.getName().equals("show")){
				oMethod1 = method;
			}
		}
		A a = new A();
		try {
			long time = System.currentTimeMillis(); 
			for(int index=0;index <=100000;index++){
				oMethod.setAccessible(true);
				oMethod.invoke(a, null);
			}
			time = System.currentTimeMillis() - time;
			System.out.println("");
		    System.out.println("oMethod: " + time + " ms"); 
		    
		    time = System.currentTimeMillis(); 
			for(int index=0;index <=100000;index++){
				oMethod1.setAccessible(true);
				oMethod1.invoke(a, null);
			}
			time = System.currentTimeMillis() - time;  
			System.out.println("");
		    System.out.println("oMethod1: " + time + " ms"); 
		    
		    time = System.currentTimeMillis(); 
		    for(int index=0;index <=100000;index++){
		    	a.show();
		    }
		    time = System.currentTimeMillis() - time;  
		    System.out.println("");
		    System.out.println("oMethod2: " + time + " ms"); 
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public static class A{
		private void show(){
			System.out.print("private");
		}
		
		public void  showA(){
			System.out.print("public");
		}
	}
	
	
	
	
//	//连接本地的 Redis 服务
//	Jedis jedis = new Jedis("192.168.2.160", 6379);
//    jedis.auth("123456");
//    jedis.connect();
//    System.out.println("连接成功");
//    //查看服务是否运行
//    System.out.println("服务正在运行: "+jedis.ping());
//    
//    jedis.close();
	
//	JedisPoolConfig config = new JedisPoolConfig();
////	config.setM.setMaxActive(1024);
//	config.setMaxIdle(200);
////	config.setMaxWait(10000);
//	config.setTestOnBorrow(true);
//	
//	//创建jedis连接池  
//    JedisPool pool = new JedisPool(config, "192.168.2.160", 6379, 5000, "123456");  
//    //从连接池中获得Jedis对象  
//    Jedis jedis = pool.getResource();  
//    jedis.auth("123456");
//    System.out.println("服务正在运行: "+jedis.ping());
//    //关闭jedis对象  
//    jedis.close();  
//    pool.close();
	
}
